package com.orhon.smartcampus.utils;


import com.alibaba.fastjson.JSONObject;
import com.orhon.smartcampus.basicComponents.GQLLang;
import org.apache.commons.lang.StringUtils;


/**
 * 多语言模糊搜索工具类
 */
public class LangUtil {

	
	public static String decide(String fieldName,Object obj){
		String hql = "";
		if(StringUtils.isNotBlank(obj.toString())){
			GQLLang name = JSONObject.parseObject(obj.toString(),GQLLang.class);
			hql += " and (";
			if(name.getZh()!=null){
				String[] string = name.getZh().split("_");
				if(hql.indexOf(fieldName) == -1){
					if(string[0].equals("like")){
						hql += fieldName+" like '%"+string[1]+"%'";
					}
				}else{
					hql += " or " +fieldName+ " like '%"+string[1]+"%'";
				}
			}
			if(name.getEn()!=null){
				String[] string = name.getEn().split("_");
				if(hql.indexOf("gradeName") == -1){
					if(string[0].equals("like")){
						hql += fieldName+" like '%"+string[1]+"%'";
					}
				}else{
					hql += " or " +fieldName+ " like '%"+string[1]+"%'";
				}
			}
			if(name.getMn()!=null){
				String[] string = name.getMn().split("_");
				if(hql.indexOf("gradeName") == -1){
					if(string[0].equals("like")){
						hql += fieldName+" like '%"+string[1]+"%'";
					}
				}else{
					hql += " or " +fieldName+ " like '%"+string[1]+"%'";
				}
			}
			hql += ")";
		}
		return hql;
    }
}
